package lang

import (
	"jvmgo/native"
	"jvmgo/rtda"
)

func init() {
	native.Register("java/lang/Thread", "currentThread", "()Ljava/lang/Thread;", currentTread)
	native.Register("java/lang/Thread", "setPriority0", "(I)V", setPriority0)
	native.Register("java/lang/Thread", "isAlive", "()Z", isAlive)
	native.Register("java/lang/Thread", "start0", "()V", start0)
}

func currentTread(frame *rtda.Frame) {
	classLoader := frame.Method().Class().Loader()
	threadClass := classLoader.LoadClass("java/lang/Thread")
	jThread := threadClass.NewObject()
	threadGroupClass := classLoader.LoadClass("java/lang/ThreadGroup")
	jGroup := threadGroupClass.NewObject()
	jThread.SetRefVar("group", "Ljava/lang/ThreadGroup;", jGroup)
	jThread.SetIntVar("priority", "I", 1)
	frame.OperandStack().PushRef(jThread)
}

func setPriority0(frame *rtda.Frame) {
	//vars := frame.LocalVars()
	//this := vars.GetThis()
	//newPriority := vars.GetInt(1)
	//fmt.Println(this, newPriority)
}

func isAlive(frame *rtda.Frame) {
	frame.OperandStack().PushBoolean(false)
}

func start0(frame *rtda.Frame) {

}
